//
//  NoGetProprietorCardView.swift
//  SmartHousekeeper
//
//  Created by 张磊 on 2020/2/20.
//  Copyright © 2020 LS. All rights reserved.
//

import UIKit
//未领卡页面
func RGBColor(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> UIColor {
    return UIColor.init(red: (r/255.0), green: (g/255.0), blue: (b/255.0), alpha: a)
}

class NoGetProprietorCardView: UIView {
    
    typealias NoGetProprietorCardViewBtnBlock = ()->()
    public var getBtnBlock : NoGetProprietorCardViewBtnBlock? = nil
    
    lazy var residentialQuartersLabel : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 122, g: 122, b: 122, a: 1), textFont: UIFont.systemFont(ofSize: Adapter(13)))
        return value
    }()
    lazy var name : UILabel = {
        let value = UILabel(textColor: .black, textFont: UIFont.systemFont(ofSize: Adapter(20)))
        return value
    }()
    lazy var phone : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 122, g: 122, b: 122, a: 1), textFont: UIFont.systemFont(ofSize: Adapter(13)))
        return value
    }()
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUi()
    }
    private func setUi(){
        
        let line = UIView()
        line.backgroundColor = RGBColor(r: 214, g: 214, b: 214, a: 1)
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(Adapter(70))
            make.left.equalToSuperview().offset(Adapter(10));
            make.right.equalToSuperview().offset(Adapter(-10));
            make.height.equalTo(0.8)
        }
        
        let cardType = UILabel(textColor: .black, textFont: UIFont.boldSystemFont(ofSize: Adapter(20)))
        cardType.text = "业主服务卡"
        self .addSubview(cardType)
        cardType.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(Adapter(20))
            make.top.equalToSuperview().offset(Adapter(15))
            make.height.equalTo(Adapter(20))
        }
        
        
        name.text = "六神"
        name.textAlignment = .right
        self.addSubview(name)
        name.snp.makeConstraints { (make) in
            make.centerY.equalTo(cardType)
            make.right.equalToSuperview().offset(Adapter(-20))
            make.height.equalTo(Adapter(20))
        }
        
        residentialQuartersLabel.text = "建宁家园小区"
        self.addSubview(residentialQuartersLabel)
        residentialQuartersLabel.snp.makeConstraints { (make) in
            make.left.equalTo(cardType)
            make.height.equalTo(Adapter(15))
            make.bottom.equalTo(line.snp.bottom).offset(Adapter(-15))
        }
        
        phone.text = "13614597056"
        phone.textAlignment = .right
        self.addSubview(phone)
        phone.snp.makeConstraints { (make) in
            make.right.equalTo(name)
            make.height.equalTo(Adapter(15))
            make.centerY.equalTo(residentialQuartersLabel)
        }
        
        let getBtn = UIButton(textColor: .white, textFont: UIFont.boldSystemFont(ofSize: Adapter(17)))
        getBtn.setTitle("立即领取", for: .normal)
        getBtn.backgroundColor = RGBColor(r: 62, g: 134, b: 230, a: 1)
        getBtn.layer.cornerRadius = Adapter(8)
        getBtn.layer.masksToBounds = true
        self.addSubview(getBtn)
        getBtn.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().offset(Adapter(-50))
            make.height.equalTo(Adapter(45))
            make.left.equalToSuperview().offset(Adapter(60))
            make.right.equalToSuperview().offset(Adapter(60))
        }
        getBtn.addTarget(self, action: #selector(getBtnAction), for: .touchUpInside)
        
        
        let neverGet = UILabel(textColor: RGBColor(r: 185, g: 160, b: 130, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(22)))
        neverGet.text = "从未领取过"
        self .addSubview(neverGet)
        neverGet.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
        }
        
        let information = UILabel(textColor: RGBColor(r: 116, g: 116, b: 116, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(15)))
        information.text = "业主需要核验身份和\n房产证信息"
        information.numberOfLines = 0
        information.textAlignment = .center
        self .addSubview(information)
        information.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(neverGet.snp.bottom).offset(Adapter(15));
        }
        
        let imgLogo = UIImageView(image: UIImage(named: "icon_house"))
        self.addSubview(imgLogo)
        imgLogo.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(neverGet.snp.top).offset(-Adapter(15));
            make.size.equalTo(CGSize(width: Adapter(60), height: Adapter(60)))

        }
        
    }
    @objc private func  getBtnAction(){
        if getBtnBlock != nil {
            getBtnBlock!()
        }
    }
}
